package collections;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

/**
 * Description:
 * <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a> 
 * <br/>Copyright (C), 2001-2012, Yeeku.H.Lee
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:
 * @author Yeeku.H.Lee kongyeeku@163.com
 * @version 1.0
 */
public class IteratorErrorTest
{
	public static void main(String[] args) 
	{
		//创建一个集合
		Collection<String> books = new HashSet<String>();
		books.add("轻量级Java EE企业应用实战");
		books.add("疯狂Java讲义");
		books.add("疯狂Android讲义");
		//获取books集合对应的迭代器
		Iterator<String> it = books.iterator();
		while(it.hasNext()){
			String book = it.next();
			System.out.println(book);
			if (book.equals("疯狂Android讲义")){
				//使用Iterator迭代过程中，不可修改集合元素,下面代码引发异常
				books.remove(book);
			}
		}
	}
}

